package com.xl.xlservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xl.xlservice.client.OrderClient;
import com.xl.xlservice.mapper.UserMapper;
import com.xl.xlservice.model.Order;
import com.xl.xlservice.model.User;
import com.xl.xlservice.service.UserService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Autowired
    private OrderClient orderClient;

    @Override
    @GlobalTransactional
    public void addUser(User user) {
        userMapper.insert(user);
        Order order = new Order();
        order.setId(user.getId());
        order.setOrderCode("orderCode" + user.getUserName());
        orderClient.addOrder(order);

        if(user.getId().equals(6)){
            throw new RuntimeException("123");
        }
    }

    @Override
    public List<User> queryUser(User user) {
        return userMapper.selectList(new QueryWrapper<User>().eq("id",user.getId()));
    }

    @Override
    public List<Order> queryOrder(Order order) {
//        Integer a = null;
//        if (a == 1){
//        }
        return orderClient.queryOrder(order);
    }

}
